package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.AlbumStat;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface AlbumStatMapper extends BaseMapper<AlbumStat> {

    @Update("update album_stat set stat_num = stat_num + #{count} where album_id =#{albumId} and stat_type =#{type} and is_deleted =0")
    int increaseStatNum(@Param("albumId") Long albumId, @Param("type") String albumStatType, @Param("count") Integer count);

    @Select("""
    select album_id,
     max(if(stat_type = 0401,stat_num,0)) playStatNum,
     max(if(stat_type = 0402,stat_num,0)) subscribeStatNum,
     max(if(stat_type = 0403,stat_num,0)) buyStatNum,
     max(if(stat_type = 0404,stat_num,0)) commentStatNum
     from album_stat where album_id =#{albumId} and is_deleted =0
     group by album_id
    """)
    AlbumStatVo getAlbumStat(@Param("albumId") Long albumId);
}
